/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgScene
    {
        private readonly Dictionary<int, CfgScene> _dataMap;
        private readonly List<CfgScene> _dataList;


        public TbCfgScene(ByteBuf _buf)
        {
            //first read common data
            _TbCommonScene _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonScene(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgScene>(size * 3 / 2);
            _dataList = new List<CfgScene>(size);

            for (int i = 0; i < size; i++)
            {
                CfgScene _v;
                _v = CfgScene.DeserializeCfgScene(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgScene> DataMap => _dataMap;
        public IReadOnlyList<CfgScene> DataList => _dataList;

        public CfgScene Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgScene] config not found,id:" + key.ToString());

            return null;
        }

        public CfgScene GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "scene";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgScene LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgScene(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgScene
    {
        private CfgScene(ByteBuf _buf, _TbCommonScene _commonData)
        {
            Id = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; SceneName = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; NavMesh = _commonData._field1[dataIndex]; }
            DefaultTime = _buf.ReadInt();
            DefaultRamp = _buf.ReadFloat();
            BgmAudioId = _buf.ReadInt();
            DefaultGround = _buf.ReadInt();
            DefaultCamera = _buf.ReadInt();
            BlockLoad = _buf.ReadBool();
            BlockCountX = _buf.ReadInt();
            BlockCountZ = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; BlockOffset = _commonData._field2[dataIndex]; }

            PostInit();
        }

        internal static CfgScene DeserializeCfgScene(ByteBuf _buf, _TbCommonScene _commonData)
        {
            return new CfgScene(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 场景资源
        /// </summary>
        public string SceneName { get; private set; }
        /// <summary>
        /// 寻路网格
        /// </summary>
        public string NavMesh { get; private set; }
        /// <summary>
        /// 默认时间(0-23、-1为主城时间)
        /// </summary>
        public int DefaultTime { get; private set; }
        /// <summary>
        /// 场景实体默认色阶值
        /// </summary>
        public float DefaultRamp { get; private set; }
        /// <summary>
        /// 默认BGM
        /// </summary>
        public int BgmAudioId { get; private set; }
        /// <summary>
        /// 默认场景地面类型
        /// </summary>
        public int DefaultGround { get; private set; }
        /// <summary>
        /// 默认场景镜头
        /// </summary>
        public int DefaultCamera { get; private set; }
        /// <summary>
        /// 是否是分块场景
        /// </summary>
        public bool BlockLoad { get; private set; }
        /// <summary>
        /// x轴块的数量
        /// </summary>
        public int BlockCountX { get; private set; }
        /// <summary>
        /// z轴块的数量
        /// </summary>
        public int BlockCountZ { get; private set; }
        /// <summary>
        /// 1-1起点块的偏移
        /// </summary>
        public IReadOnlyList<float> BlockOffset { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonScene
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<float>> _field2 { get; private set; }
        internal _TbCommonScene(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new float[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ float[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new float[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ float __v1; __v1 = _buf.ReadFloat(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
